package br.com.hotel.dao;

import java.util.ArrayList; 
import java.util.Date;
import java.util.List;

import br.com.hotel.bean.Utils;
import br.com.hotel.entity.Diaria;

public class DiariaDAO extends GenericJpaRepository<Diaria, Long>{

	public List<Diaria> diaria;
	public DiariaDAO() throws ClassNotFoundException{
		createEntityManager();
	}
	
	public List<Diaria> getDiarias(){
		
		return findAll();
	}
	public Boolean freeDiaria(Date inicial,Date ffinal,Long id){
		javax.persistence.Query query = getEntityManager().createQuery("SELECT  p FROM Estadia p, Diaria d WHERE p.diaria.id=d.id AND (p.data_inicial<=?1 AND p.data_final>=?2) OR (p.data_inicial<=?3 AND p.data_final>=?4)");
		query.setParameter(1, inicial).setParameter(2, inicial).setParameter(3, ffinal).setParameter(4, ffinal);
		if(query.getResultList().size()!=0)
			return false;
		return true;
	}
	
	
	//impedir diarias para mesmo apartamento
	public List<Diaria> getDiariaPorApartamento(){
		javax.persistence.Query query = getEntityManager().createQuery("SELECT  count(*) as tem FROM Diaria p WHERE p.apartamento_id=?1");
		query.setParameter(1, new Date());
		return query.getResultList();
	}
	
}